/*
 * 
 */

package sifApp.sifAppDataBaseHelper;

import java.util.ArrayList;

import sifApp.SifAppEntity.Albums;
import sifApp.SifAppEntity.CommentsAlbums;
import sifApp.SifAppEntity.CommentsPhotos;
import sifApp.SifAppEntity.Friends;
import sifApp.SifAppEntity.LikesAlbums;
import sifApp.SifAppEntity.LikesPhotos;
import sifApp.SifAppEntity.NewsFeed;
import sifApp.SifAppEntity.Photos;
import sifApp.SifAppEntity.ProfileFeed;
import sifApp.SifAppEntity.TagsPhotos;
import sifApp.SifAppEntity.User;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

/**
 * SQLiteProvider
 * @author Manhphitu
 *
 */
public class SQLiteProvider {
	private SQLiteDatabase sqLiteDatabase;
	public static SQLiteProvider instance = null;
	private Context context;
	private String packageName;

	/**
	 * Gets the single instance of SQLiteProvider.
	 * 
	 * @param context
	 *            the context
	 * @param packageName
	 *            the package name
	 * @return single instance of SQLiteProvider
	 */
	public static SQLiteProvider getInstance(Context context, String packageName) {
		if (instance == null) {
			instance = new SQLiteProvider(context, packageName);
		}
		return instance;
	}

	/**
	 * Instantiates a new sQ lite provider.
	 * 
	 * @param context
	 *            the context
	 * @param packageName
	 *            the package name
	 */
	public SQLiteProvider(Context context, String packageName) {
		this.context = context;
		this.packageName = packageName;
	}

	// set void of User
	/**
	 * Add new a User
	 * 
	 * @param user
	 */

	public void addUser(User user) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			ContentValues values = new ContentValues();
			values.put("id", user.getId());
			values.put("name", user.getName());
			values.put("first_name", user.getFirst_name());
			values.put("last_name", user.getLast_name());
			values.put("link", user.getLink());
			values.put("username", user.getUsername());
			values.put("gender", user.getGender());
			values.put("locale", user.getLocale());
			values.put("email", user.getEmail());
			sqLiteDatabase.insert("TbUsers", null, values);
			sqLiteDatabase.close();
			databaseHelper.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * get User Facebook
	 * 
	 * @param idUser
	 * @return
	 */
	public User getUser(String idUser) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		User user = new User();
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			Cursor c = sqLiteDatabase.rawQuery("select * from " + "TbUsers"
					+ "id=" + idUser, null);

			if (c != null) {
				if (c.moveToFirst()) {
					do {

						user.setId(c.getString(c.getColumnIndex("id")));
						user.setName(c.getString(c.getColumnIndex("name")));
						user.setFirst_name(c.getString(c
								.getColumnIndex("first_name")));
						user.setLast_name(c.getString(c
								.getColumnIndex("last_name")));
						user.setLink(c.getString(c.getColumnIndex("link")));
						user.setUsername(c.getString(c
								.getColumnIndex("username")));
						user.setGender(c.getString(c.getColumnIndex("gender")));
						user.setLocale(c.getString(c.getColumnIndex("locale")));
						user.setEmail(c.getString(c.getColumnIndex("email")));
					} while (c.moveToNext());
				}
				c.close();
				sqLiteDatabase.close();
				databaseHelper.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		// return contact
		return user;
	}

	/**
	 * add a new Friend
	 * 
	 * @param riend
	 */
	public void addFriend(Friends riend) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			ContentValues values = new ContentValues();
			values.put("id", riend.getId());
			values.put("myAccountId", riend.getMyAccountId());
			values.put("name", riend.getName());
			values.put("image", riend.getImage());
			sqLiteDatabase.insert("TbFriends", null, values);
			sqLiteDatabase.close();
			databaseHelper.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * get all friend of a User
	 * 
	 * @param id
	 * @return
	 */
	public ArrayList<Friends> getAllFriends() {
		ArrayList<Friends> arrayList = new ArrayList<Friends>();
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			Cursor c = sqLiteDatabase.rawQuery("select * from " + "TbFriends",
					null);
			if (c != null) {
				if (c.moveToFirst()) {
					do {
						Friends friend = new Friends();
						friend.setId(c.getString(c.getColumnIndex("id")));
						friend.setMyAccountId(c.getString(c.getColumnIndex("myAccountId")));
						friend.setName(c.getString(c.getColumnIndex("name")));
						friend.setImage(c.getString(c.getColumnIndex("image")));
						arrayList.add(friend);
					} while (c.moveToNext());
				}
			}
			c.close();
			sqLiteDatabase.close();
			databaseHelper.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return arrayList;
	}
/**
 * add a new News Feed
 * @param newFeed
 */
	public void addNewFeed(NewsFeed newFeed) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			ContentValues values = new ContentValues();
			values.put("id", newFeed.getId());
			values.put("myAccountId", newFeed.getMyAccountId());
			values.put("fromId", newFeed.getFromId());
			values.put("fromName", newFeed.getFromName());
			values.put("message", newFeed.getMessage());
			values.put("picture", newFeed.getPicture());
			values.put("link", newFeed.getLink());
			values.put("icon", newFeed.getIcon());
			values.put("type", newFeed.getType());
			values.put("object_id", newFeed.getObject_id());
			values.put("like_count", newFeed.getLikes_count());
			values.put("comment_count", newFeed.getComment_count());
			sqLiteDatabase.insert("TbNewsFeed", null, values);
			sqLiteDatabase.close();
			databaseHelper.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * get all News Feed of a User Facebook
	 * @return
	 */
	public ArrayList<NewsFeed> getAllNewsFeed() {
		ArrayList<NewsFeed> arrayList = new ArrayList<NewsFeed>();
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			Cursor c = sqLiteDatabase.rawQuery("select * from " + "TbNewsFeed",
					null);
			if (c != null) {
				if (c.moveToFirst()) {
					do {
						NewsFeed newsfeed = new NewsFeed();
						newsfeed.setId(c.getString(c.getColumnIndex("id")));
						newsfeed.setMyAccountId(c.getString(c.getColumnIndex("myAccountId")));
						newsfeed.setFromId(c.getString(c.getColumnIndex("fromId")));
						newsfeed.setFromName(c.getString(c.getColumnIndex("fromName")));
						newsfeed.setMessage(c.getString(c.getColumnIndex("message")));
						newsfeed.setPicture(c.getString(c.getColumnIndex("picture")));
						newsfeed.setLink(c.getString(c.getColumnIndex("link")));
						newsfeed.setIcon(c.getString(c.getColumnIndex("icon")));
						newsfeed.setType(c.getString(c.getColumnIndex("type")));
						newsfeed.setObject_id(c.getString(c.getColumnIndex("object_id")));
						newsfeed.setLikes_count(c.getString(c.getColumnIndex("like_count")));
						newsfeed.setComment_count(c.getString(c.getColumnIndex("comment_count")));
						
						arrayList.add(newsfeed);
					} while (c.moveToNext());
				}
			}
			c.close();
			sqLiteDatabase.close();
			databaseHelper.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return arrayList;
	}
	/**
	 * add tags of photo
	 * @param tagsphotos
	 */
	public void addTagsPhotos(TagsPhotos tagsphotos) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			ContentValues values = new ContentValues();
			values.put("id", tagsphotos.getId());
			values.put("idPhotos", tagsphotos.getIdPhotos());
			values.put("name", tagsphotos.getName());
			sqLiteDatabase.insert("TbTagsPhotos", null, values);
			sqLiteDatabase.close();
			databaseHelper.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * get all tags photo
	 * @return arrayList
	 */
	public ArrayList<TagsPhotos> getAllTagsPhotos() {
		ArrayList<TagsPhotos> arrayList = new ArrayList<TagsPhotos>();
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			Cursor c = sqLiteDatabase.rawQuery("select * from " + "TbTagsPhotos",
					null);
			if (c != null) {
				if (c.moveToFirst()) {
					do {
						TagsPhotos tagsphotos = new TagsPhotos();
						tagsphotos.setId(c.getString(c.getColumnIndex("id")));
						tagsphotos.setIdPhotos(c.getString(c.getColumnIndex("idPhotos")));
						tagsphotos.setName(c.getString(c.getColumnIndex("name")));
						
						arrayList.add(tagsphotos);
					} while (c.moveToNext());
				}
			}
			c.close();
			sqLiteDatabase.close();
			databaseHelper.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return arrayList;
	}
	/**
	 * add like of photo
	 * @param likesphotos
	 */
	public void addLikesPhotos(LikesPhotos likesphotos) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			ContentValues values = new ContentValues();
			values.put("id", likesphotos.getId());
			values.put("idPhotos", likesphotos.getIdPhotos());
			values.put("name", likesphotos.getName());
			sqLiteDatabase.insert("TbLikesPhotos", null, values);
			sqLiteDatabase.close();
			databaseHelper.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * get all like of photo
	 * @return arrayList
	 */
	public ArrayList<LikesPhotos> getAllLikesPhotos() {
		ArrayList<LikesPhotos> arrayList = new ArrayList<LikesPhotos>();
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			Cursor c = sqLiteDatabase.rawQuery("select * from " + "TbLikesPhotos",
					null);
			if (c != null) {
				if (c.moveToFirst()) {
					do {
						LikesPhotos tagsphotos = new LikesPhotos();
						tagsphotos.setId(c.getString(c.getColumnIndex("id")));
						tagsphotos.setIdPhotos(c.getString(c.getColumnIndex("idPhotos")));
						tagsphotos.setName(c.getString(c.getColumnIndex("name")));
						
						arrayList.add(tagsphotos);
					} while (c.moveToNext());
				}
			}
			c.close();
			sqLiteDatabase.close();
			databaseHelper.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return arrayList;
	}
	/**
	 * add comments photo
	 * @param commentsphotos
	 */
	public void addCommentsPhotos(CommentsPhotos commentsphotos) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			ContentValues values = new ContentValues();
			values.put("id", commentsphotos.getId());
			values.put("idPhotos", commentsphotos.getIdPhotos());
			values.put("message", commentsphotos.getMessage());
			sqLiteDatabase.insert("TbCommentsPhotos", null, values);
			sqLiteDatabase.close();
			databaseHelper.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * get all comment of photo
	 * @return arrayList
	 */
	public ArrayList<CommentsPhotos> getAllCommentsPhotos() {
		ArrayList<CommentsPhotos> arrayList = new ArrayList<CommentsPhotos>();
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			Cursor c = sqLiteDatabase.rawQuery("select * from " + "TbCommentsPhotos",
					null);
			if (c != null) {
				if (c.moveToFirst()) {
					do {
						CommentsPhotos commentsphotos = new CommentsPhotos();
						commentsphotos.setId(c.getString(c.getColumnIndex("id")));
						commentsphotos.setIdPhotos(c.getString(c.getColumnIndex("idPhotos")));
						commentsphotos.setMessage(c.getString(c.getColumnIndex("message")));
						
						arrayList.add(commentsphotos);
					} while (c.moveToNext());
				}
			}
			c.close();
			sqLiteDatabase.close();
			databaseHelper.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return arrayList;
	}
	/**
	 * add profile feed
	 * @param profilefeed
	 */
	public void addProfileFeed(ProfileFeed profilefeed) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			ContentValues values = new ContentValues();
			values.put("id", profilefeed.getId());
			values.put("myAccountId", profilefeed.getMyAccountId());
			values.put("fromId", profilefeed.getFromId());
			values.put("fromName", profilefeed.getFromName());
			values.put("story", profilefeed.getStory());
			values.put("picture", profilefeed.getPicture());
			values.put("link", profilefeed.getLink());
			values.put("description", profilefeed.getDescription());
			values.put("icon", profilefeed.getIcon());
			values.put("type", profilefeed.getType());
			values.put("object_id", profilefeed.getObject_id());
			values.put("likes_count", profilefeed.getLikes_count());
			values.put("comments_count", profilefeed.getComments_count());
			sqLiteDatabase.insert("TbProfileFeed", null, values);
			sqLiteDatabase.close();
			databaseHelper.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * get all profile feed
	 * @return
	 */
	public ArrayList<ProfileFeed> getAllProfileFeed() {
		ArrayList<ProfileFeed> arrayList = new ArrayList<ProfileFeed>();
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			Cursor c = sqLiteDatabase.rawQuery("select * from " + "TbProfileFeed",
					null);
			if (c != null) {
				if (c.moveToFirst()) {
					do {
						ProfileFeed profilefeed = new ProfileFeed();
						profilefeed.setId(c.getString(c.getColumnIndex("id")));
						profilefeed.setMyAccountId(c.getString(c.getColumnIndex("myAccountId")));
						profilefeed.setFromId(c.getString(c.getColumnIndex("fromId")));
						profilefeed.setFromName(c.getString(c.getColumnIndex("fromName")));
						profilefeed.setStory(c.getString(c.getColumnIndex("story")));
						profilefeed.setPicture(c.getString(c.getColumnIndex("picture")));
						profilefeed.setLink(c.getString(c.getColumnIndex("link")));
						profilefeed.setDescription(c.getString(c.getColumnIndex("description")));
						profilefeed.setIcon(c.getString(c.getColumnIndex("icon")));
						profilefeed.setType(c.getString(c.getColumnIndex("type")));
						profilefeed.setObject_id(c.getString(c.getColumnIndex("object_id")));
						profilefeed.setLikes_count(c.getString(c.getColumnIndex("likes_count")));
						profilefeed.setComments_count(c.getString(c.getColumnIndex("comments_count")));
						
						
						arrayList.add(profilefeed);
					} while (c.moveToNext());
				}
			}
			c.close();
			sqLiteDatabase.close();
			databaseHelper.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return arrayList;
	}
	/**
	 * add photos
	 * @param photos
	 */
	public void addPhotos(Photos photos) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			ContentValues values = new ContentValues();
			values.put("id", photos.getId());
			values.put("myAccountId", photos.getMyAccountId());
			values.put("fromId", photos.getFromid());
			values.put("fromName", photos.getFromName());
			values.put("picture", photos.getPicture());
			values.put("source", photos.getSource());
			values.put("link", photos.getLink());
			values.put("icon", photos.getIcon());
			sqLiteDatabase.insert("TbPhotos", null, values);
			sqLiteDatabase.close();
			databaseHelper.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * get all photo
	 * @return
	 */
	public ArrayList<Photos> getAllPhotos() {
		ArrayList<Photos> arrayList = new ArrayList<Photos>();
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			Cursor c = sqLiteDatabase.rawQuery("select * from " + "TbPhotos",
					null);
			if (c != null) {
				if (c.moveToFirst()) {
					do {
						Photos photos = new Photos();
						photos.setId(c.getString(c.getColumnIndex("id")));
						photos.setMyAccountId(c.getString(c.getColumnIndex("myAccountId")));
						photos.setFromid(c.getString(c.getColumnIndex("fromId")));
						photos.setFromName(c.getString(c.getColumnIndex("fromName")));
						photos.setPicture(c.getString(c.getColumnIndex("picture")));
						photos.setSource(c.getString(c.getColumnIndex("source")));
						photos.setLink(c.getString(c.getColumnIndex("link")));
						photos.setIcon(c.getString(c.getColumnIndex("icon")));
						
						arrayList.add(photos);
					} while (c.moveToNext());
				}
			}
			c.close();
			sqLiteDatabase.close();
			databaseHelper.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return arrayList;
	}
	/**
	 * add like album
	 * @param likesAlbums
	 */
	public void addLikesAlbums(LikesAlbums likesAlbums) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			ContentValues values = new ContentValues();
			values.put("id", likesAlbums.getId());
			values.put("idAlbums", likesAlbums.getIdAlbums());
			values.put("name", likesAlbums.getName());
			sqLiteDatabase.insert("TbLikesAlbums", null, values);
			sqLiteDatabase.close();
			databaseHelper.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * get all like of album
	 * @return arrayList
	 */
	public ArrayList<LikesAlbums> getAllLikesAlbums() {
		ArrayList<LikesAlbums> arrayList = new ArrayList<LikesAlbums>();
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			Cursor c = sqLiteDatabase.rawQuery("select * from " + "TbLikesAlbums",
					null);
			if (c != null) {
				if (c.moveToFirst()) {
					do {
						LikesAlbums likesAlbums = new LikesAlbums();
						likesAlbums.setId(c.getString(c.getColumnIndex("id")));
						likesAlbums.setIdAlbums(c.getString(c.getColumnIndex("idAlbums")));
						likesAlbums.setName(c.getString(c.getColumnIndex("name")));
						
						arrayList.add(likesAlbums);
					} while (c.moveToNext());
				}
			}
			c.close();
			sqLiteDatabase.close();
			databaseHelper.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return arrayList;
	}
	/**
	 * add comment album
	 * @param commentsAlbums
	 */
	public void addCommentsAlbums(CommentsAlbums commentsAlbums) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			ContentValues values = new ContentValues();
			values.put("id", commentsAlbums.getId());
			values.put("idAlbums", commentsAlbums.getIdAlbums());
			values.put("fromid", commentsAlbums.getFromid());
			values.put("message", commentsAlbums.getMessage());
			sqLiteDatabase.insert("TbCommentsAlbums", null, values);
			sqLiteDatabase.close();
			databaseHelper.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * get all comment of album
	 * @return arrayList
	 */
	public ArrayList<CommentsAlbums> getAllCommentsAlbums() {
		ArrayList<CommentsAlbums> arrayList = new ArrayList<CommentsAlbums>();
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			Cursor c = sqLiteDatabase.rawQuery("select * from " + "TbCommentsAlbums",
					null);
			if (c != null) {
				if (c.moveToFirst()) {
					do {
						CommentsAlbums commentsAlbums = new CommentsAlbums();
						commentsAlbums.setId(c.getString(c.getColumnIndex("id")));
						commentsAlbums.setIdAlbums(c.getString(c.getColumnIndex("idAlbums")));
						commentsAlbums.setFromid(c.getString(c.getColumnIndex("fromid")));
						commentsAlbums.setMessage(c.getString(c.getColumnIndex("message")));
						
						arrayList.add(commentsAlbums);
					} while (c.moveToNext());
				}
			}
			c.close();
			sqLiteDatabase.close();
			databaseHelper.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return arrayList;
	}
	
	
	public void addAlbums(Albums albums) {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			ContentValues values = new ContentValues();
			values.put("id", albums.getId());
			values.put("myAccountId", albums.getMyAccountId());
			values.put("fromid", albums.getFromid());
			values.put("name", albums.getName());
			values.put("link", albums.getLink());
			values.put("cover_photo", albums.getCover_photo());
			values.put("count", albums.getCount());
			values.put("type", albums.getType());
			sqLiteDatabase.insert("TbAlbums", null, values);
			sqLiteDatabase.close();
			databaseHelper.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * get all comment of album
	 * @return arrayList
	 */
	public ArrayList<Albums> getAllAlbums() {
		ArrayList<Albums> arrayList = new ArrayList<Albums>();
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			Cursor c = sqLiteDatabase.rawQuery("select * from " + "TbAlbums",
					null);
			if (c != null) {
				if (c.moveToFirst()) {
					do {
						Albums albums = new Albums();
						albums.setId(c.getString(c.getColumnIndex("id")));
						albums.setMyAccountId(c.getString(c.getColumnIndex("myAccountId")));
						albums.setFromid(c.getString(c.getColumnIndex("fromid")));
						albums.setName(c.getString(c.getColumnIndex("name")));
						albums.setLink(c.getString(c.getColumnIndex("link")));
						albums.setCover_photo(c.getString(c.getColumnIndex("cover_photo")));
						albums.setCount(c.getString(c.getColumnIndex("count")));
						albums.setType(c.getString(c.getColumnIndex("type")));
						
						arrayList.add(albums);
					} while (c.moveToNext());
				}
			}
			c.close();
			sqLiteDatabase.close();
			databaseHelper.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return arrayList;
	}
	/**
	 * Clear db.
	 */
	public void clearDB() {
		SIFDataHelper databaseHelper = SIFDataHelper.getInstance(context,
				packageName);
		try {
			sqLiteDatabase = databaseHelper.openDataBase();
			sqLiteDatabase.delete("barcode", null, null);
			sqLiteDatabase.close();
			databaseHelper.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
